<?php
namespace app\cms\model;

/**
 * 导航模型
 * @author FamilyTree
 */

class Menu extends Base {

    protected $_validate = array(
        array('url','require','url必须填写'), //默认情况下用正则进行验证
    );
    
    //获取树的根到子节点的路径
    public function getPath($id){
        $path = array();
        $nav = $this->where("id={$id}")->field('id,pid,title')->find();
        $path[] = $nav;
        if($nav['pid'] >1){
            $path = array_merge($this->getPath($nav['pid']),$path);
        }
        return $path;
    }
    /**
     * 获取已有菜单列表
     * @return NULL[]
     */
    public function pdata(){
        $data = $this->field('id,title')->where(['status'=>1])->select();
        
        $pdata = [];
        foreach ($data as $val){
            $pdata[$val['id']] = $val->data;
        }
        return $pdata;
    }
}

